import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(
    // home: Scaffold(
    //   appBar: AppBar(
    //     title: const Text('页面架子'),
    //     backgroundColor: Colors.blue,
    //   ),
    //   body: MyInfo(name: 'jack', age: 18),
    // ),
    home: MyCounter(),
  ));
}

//1.无状态组件
//fstless
// class MyInfo extends StatelessWidget {
//   const MyInfo({super.key});

//   @override
//   Widget build(BuildContext context) {
//     return const Center(
//       child: Text('我是谁 今年多少岁'),
//     );
//   }
// }

class MyInfo extends StatelessWidget {
  MyInfo({super.key, required this.name, required this.age});

  String name;
  int age;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text('$name 今年 $age  岁'),
    );
  }
}

//有状态组件
class MyCounter extends StatefulWidget {
  const MyCounter({super.key});

  @override
  _MainState createState() => _MainState();
}

class _MainState extends State<MyCounter> {
  int count = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('计数器组件'),
        backgroundColor: Colors.pink,
      ),
      body: Center(
        child: Text(count.toString()),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            count++;
          });
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}
